#define DEBUG
#include <cstdio>
#include <cstring>
#include <cassert>
#define MODS 1000000007
#define MAXN 3000
#define MAXLEN 3000

using namespace std;

int fact[MAXN+1];

void sort(char *a[MAXN+1], int l, int r) {
  int i=l, j=r;
  char *mid=a[(l+r)/2], *temp;
  for (; i<=j; ) {
    for (; strcmp(a[j]+1, mid+1)>0; j--);
    for (; strcmp(a[i]+1, mid+1)<0; i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r);
  }
  if (j>l) {
    sort(a, l, j);
  }
}

long long solve(int l, int r, int dep, char *name[]) {
  if (l==r) {
    return 1;
  } else {
    long long ret=1, cnt=0;
    int tl=l;
    for (int i=l; i<r; i++) {
      if (name[i][dep]!=name[i+1][dep]) {
	if (name[i][dep]) {
	  ret = ret*solve(tl, i, dep+1, name)%MODS;
	} else {
	  ret = ret*fact[i-tl+1]%MODS;
	}
	tl = i+1;
	cnt++;
      }
    }
    cnt++;
    if (name[r][dep]) {
      ret = ret*solve(tl, r, dep+1, name)%MODS;
    } else {
      ret = ret*fact[r-tl+1]%MODS;
    }
    return ret*fact[cnt]%MODS;
  }
}

void initFact(int n) {
  fact[0]=1;
  for (long long i=1; i<=n; i++) {
    fact[i] = fact[i-1]*i%MODS;
  }
}

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif

  static char str[MAXN+1][MAXLEN+2], *name[MAXN+1];
  int n;
  scanf("%d", &n);
  initFact(n);
  for (int i=1; i<=n; i++) {
    scanf("%s", str[i]+1);
    name[i] = str[i];
  }
  
  sort(name, 1, n);

  printf("%lld", solve(1, n, 1, name));
  
  fcloseall();
  return 0;
}
